package ControllerLayer;

import ModelLayer.*;

import java.util.ArrayList;


/**
 * This is a controller class for the address book.
 * 
 * @author Group 4, dm82
 * @version 07-12-12
 */
public class AddressCtr
{
    private static AddressCtr   instance;
    private AddressBook         addressBook;
    private static long         idCount;
    /**
     * Constructor for objects of class AddressCtr
     */
    private AddressCtr()
    {
        idCount = 0;
        addressBook = AddressBook.getInstance();
    }
    
    /**
     * This method returns an instance of this class.
     */
    public static AddressCtr getInstance()
    {
        if(instance == (null))
        {
            instance = new AddressCtr();
        }
        return instance;
    }
    
    /**
     * This method returns a Person.
     * 
     * @param   id  The id of the Person. as a long.
     * 
     * @return  A Person.
     */
    public Person getPerson(long id)
    {
        return addressBook.findPersonById(id);
    }
    
    /**
     * This method creates a new employee.
     * 
     * @param   id          The persons id. As a long.
     * @param   name        The name of the person. As a String.
     * @param   address     The persons address. As a String.
     * @param   phoneNumber The persons phone number. As a String.
     * @param   email       The persons email address. As a String.
     */
    public void createEmployee(String name, String address, String phoneNumber, String email, String password)
    {
        idCount++;
        Employee employee = new Employee(idCount, name, address, phoneNumber, email, password);
        addressBook.addPerson(employee);
    }
    
    /**
     * This method creates a new customer.
     * 
     * @param   id          The persons id. As a long.
     * @param   name        The name of the person. As a String.
     * @param   address     The persons address. As a String.
     * @param   phoneNumber The persons phone number. As a String.
     * @param   email       The persons email address. As a String.
     */
    public void createCustomer(String name, String address, String phoneNumber, String email, double accountLimit, double accountBalance)
    {
        idCount++;
        Customer customer = new Customer(idCount, name, address, phoneNumber, email, accountLimit, accountBalance);
        addressBook.addPerson(customer);
    }
    
    /**
     * This method deletes a person by id.
     * 
     * @param   id  The id of the person.
     */
    public void deletePerson(long id)
    {
        addressBook.deletePersonById(id);
    }
    
    /**
     * This method returns a list of all customers
     * 
     * @return  A list of customers.
     */
    public ArrayList<Customer> getCustomerList()
    {
        return addressBook.getCustomerList();
    }
    
    public ArrayList<String> getListOfCustomers()
    {
    	return addressBook.getListOfCustomers();
    }
    
    /**
     * This method returns a list of persons.
     * 
     * @return  A list of persons.
     */
    public ArrayList<Person> getPersonList()
    {
        return addressBook.getPersonList();
    }
}
